/**
 * Created by LUOLIANG on 2016/6/20.
 */
var Commen_vm = avalon.define({
    $id: "commonController",
    pageSize: 6,
    user: {},
    pageCurrent: 1,
    topic: {},
    topiclist: {},
    commenstring: "",
    commenlist: {},

    topicDetil: function (el) {
        Commen_vm.topic = el;
        $("#commenlist").addClass('hide');
        $("#detail").removeClass('hide');

        $.ajax({
            type: 'POST',
            url: '/CounterDrops/commen/commomList',
            data: {
                topicid: Commen_vm.topic.id
            },
            success: function (data) {
                Commen_vm.commenlist = data.items;

            },
            error: function (e) {

            }
        });
    },
    userInfo: function () {
        $.ajax({
            type: "post",
            url: "/CounterDrops/weuser/currentUser",
            data: {},
            success: function (data) {
                if (data.success == true) {
                    Commen_vm.user = data.model;
                } else {
                    toastr.warning(data.msg);
                }
            }
        });
    },
    comment: function () {

        $.ajax({
            type: 'POST',
            url: '/CounterDrops/commen/commomtopic',
            data: {
                content: Commen_vm.commenstring,
                topicid: Commen_vm.topic.id,
                userid: Commen_vm.user.userid
            },
            success: function (data) {
                if (data.success) {
                    Commen_vm.topicDetil(Commen_vm.topic);
                    toastr.info("评论成功");
                } else {
                    toastr.info("评论失败");
                }

            },
            error: function (e) {
            }
        });
    },
    back: function () {
        $("#detail").addClass('hide');
        $("#commenlist").removeClass('hide');
    },
    loadcommenlist: function () {
        Commen_vm.userInfo();
        $("#detail").addClass('hide');
        $.ajax({
            type: 'POST',
            url: '/CounterDrops/topic/gettopiclist',
            data: {
                pageSize: 10000,
                pageCurrent: 1,
                keyword: ""
            },
            success: function (data) {
                Commen_vm.topiclist = data.model.results;
            },
            error: function (e) {
            }
        });
    },
});
Commen_vm.loadcommenlist();